const { build } = require("esbuild");
const path = require("path");

const esBuildScanPlugin = require("./esBuildScanPlugin");

async function scanImports(config) {
  const depImports = {};
  const esPlugin = await esBuildScanPlugin(config, depImports);
  await build({
    absWorkingDir: config.root,
    entryPoints: [path.resolve("./index.html")],
    bundle: true,
    format: "esm",
    outfile: "dist/index.js",
    write: true,
    plugins: [esPlugin],
  });

  return depImports;
}

module.exports = scanImports;
